package com.erpoa.mapper;

import com.erpoa.dto.BatchMatCombLine;
import com.erpoa.dto.BatchMatCombineMain;
import com.erpoa.entity.PackMessageByMerge;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author chenjimin
 * @Title: BatchMergeMapper
 * @ProjectName oaerp
 * @Description: TODO
 * @date 2021/1/2813:30
 */
@Mapper
public interface BatchMergeMapper {
//TODO CJM

    List<BatchMatCombineMain> selectBatchMergeToday(@Param("packMessage") PackMessageByMerge packMessage);

    @Select(" select count(1) from ds2.TC_PGEN_FILE where tc_pgen02='E' and tc_pgen03='F' and tc_pgen01=#{sCode} ")
    int queryRight(String sCode);


    @Update(" DROP SEQUENCE ${sequence} ")
    void dropSequence(@Param("sequence") String sequence);


    void createSequence(@Param("sequence") String sequence, @Param("count") String count);


    @Select(" select ${sequence}.nextval   from dual ")
    Integer getSequence(@Param("sequence") String sequence);

    @Select(" select a.COMBINENUMBER combineNumber,FMATCODE fmatcode,FBARCODE fbarcode,BFCREATEPER bfCreateper,OLDBARCODE oldBarcode,OLD_QTY oldQty, " +
            "to_char( a.BFCREATEDATE,'yyyy-MM-dd HH24:mi:ss') bfCreateDate,b.MG_STATUS  mgStatus,b.NEWBARCODE newBarCode  from  Mg_Batchmatcombline a left join Mg_Batchmatcombinemain b " +
            "            on  a.Combinenumber = b.Combinenumber " +
            "  where a.COMBINENUMBER =#{packMessage.combineNumber}  ")
    List<BatchMatCombLine> selectBatchMergeLine(@Param("packMessage") PackMessageByMerge packMessage);

    @Select(" select COMBINENUMBER combineNumber,FMATCODE fmatcode,FBARCODE fbarcode,BFCREATEPER bfCreateper,OLDBARCODE oldBarcode,OLD_QTY oldQty, " +
            "to_char( BFCREATEDATE,'yyyy-MM-dd HH24:mi:ss') bfCreateDate  from  Mg_Batchmatcombline  where COMBINENUMBER =#{packMessage.mBarcode}   ")
    List<BatchMatCombLine> selectBatchMergeLineByScan(@Param("packMessage") PackMessageByMerge packMessage);

    @Select("  select count(*) from  Mg_Batchmatcombline where combinenumber =#{packMessage.combineNumber}  ")
    int countBatchMergeLineBycombineNumber(@Param("packMessage") PackMessageByMerge packMessage);

    @Select(" select count(*) from  Mg_Batchmatcombline where instr(FBARCODE ,#{packMessage.mBarcode})>0  ")
    int countBatchMergeLineCombinenumber(@Param("packMessage") PackMessageByMerge packMessage);

    @Select("            select a.FVENDERCODE fvendercode,a.FMATCODE fmatcode,a.FTYPE ftype,a.FCOLOR fcolor, " +
            "        a.FBARCODE fbarcode,a.FBATCHNO fbatchno,to_char( a.FPRODUCTIONDATE,'yyyy-MM-dd'),a.OLD_QTY oldQty " +
            "        ,a.FRECEIVEDATE fproductiondate,a.FFACTORYCODE ffactorycode,a.FWORKSHOPCODE fworkshopcode  " +
            "         from Mg_Batchmatcombline a where COMBINENUMBER =#{packMessage.combineNumber}  ")
    BatchMatCombLine selectBatchMergeLineByNowHas(@Param("packMessage") PackMessageByMerge packMessage);


    BatchMatCombLine selectBatchMergeLineByNowHasdto(@Param("fbarcodehas") String fbarcodehas);


    int insertBatchScan(@Param("bmcls") BatchMatCombLine batchMatCombLinescan);


    int updateBatchScan(@Param("bmcls") BatchMatCombLine batchMatCombLinescan);

    @Update(" update DSX5.mg_batchMatCombineMain set NEW_QTY = #{batchMain.newQty}  where COMBINENUMBER = #{batchMain.combineNumber} ")
    int updateBatchMailScan(@Param("batchMain") BatchMatCombineMain batchMain);


    int insertBatchMailScan(@Param("batchMain") BatchMatCombineMain batchMain);

    @Select(" select fid fid,COMBINENUMBER combineNumber,FMATCODE fmatcode,FMATNAME fmatName,FBARCODE fbarcode,BFCREATEPER bfCreateper,OLDBARCODE oldBarcode,OLD_QTY oldQty, " +
            "to_char( BFCREATEDATE,'yyyy-MM-dd HH24:mi:ss') bfCreateDate,FVENDERCODE fvendercode,FCOLOR fcolor,FTYPE ftype," +
            "  to_char( FPRODUCTIONDATE,'yyyy-MM-dd') fproductiondate,to_char(FRECEIVEDATE,'yyyy-MM-dd') freceivedate from  Mg_Batchmatcombline  where COMBINENUMBER =#{packMessage.combineNumber} order by" +
            " FPRODUCTIONDATE asc  ")
    List<BatchMatCombLine> selectBatchsMergeLine(String combineNumber);

    @Select(" select COMBINENUMBER combineNumber,CREATER creater,NEWBARCODE newBarCode,MG_STATUS mgStatus,FFACTORYCODE fFactoryCode,FWORKSHOPCODE fWorkShopCode" +
            " from DSX5.MG_BATCHMATCOMBINEMAIN  WHERE  COMBINENUMBER =#{packMessage.combineNumber}   ")
    BatchMatCombineMain selectBatchMergeLineByComnumber(String combineNumber);

    @Update(" update DSX5.mg_batchMatCombineMain set NEW_QTY = #{batchMain.newQty},NEWBARCODE =#{batchMain.newBarCode} ,MG_STATUS=#{batchMain.mgStatus} where COMBINENUMBER = #{batchMain.combineNumber} ")
    int updateBatchMailnewBarCode(@Param("batchMain") BatchMatCombineMain batchMatCombineMain);

    @Delete(" delete from DSX5.Mg_Batchmatcombline where   COMBINENUMBER =#{packMessage.combineNumber} ")
    int dellineByComnumber(String combineNumber);

    @Delete(" delete from DSX5.mg_batchMatCombineMain where   COMBINENUMBER =#{packMessage.combineNumber} ")
    int delmainByComnumber(String combineNumber);


    int insertBatchmatByMain(@Param("batchMain") BatchMatCombineMain batchMatCombineMain, @Param("batchLine") BatchMatCombLine batchMatCombLine);

    @Update(" update DSX5.mg_batchMatCombineMain set MG_STATUS=#{batchMain.mgStatus} where COMBINENUMBER = #{batchMain.combineNumber} ")
    int updateBatchMailstatus(@Param("batchMain") BatchMatCombineMain batchMatCombineMain);
}
